﻿using UnityEngine;
using System.Collections;

/// <summary>
/// Player controller and behavior
/// </summary>

public class PlayerController : MonoBehaviour 
{
	// The speed of the player
	public float moveSpeed = 10f;
	// The jump of the player
	public float jumpSpeed = 150f;
	// Player Life
	int playerLife = 1;
	//cont to player begin move 
	int cont;

	// Is called before Start(). Great for references.
	void Awake()
	{
		//the timeScale begin 0
		Time.timeScale = 0.0f;
	}

	// Update is called once per frame
	void Update () 
	{
		//to cont
		cont++;
		//if the cont equal 100
		if(cont>=100)
		{
			//the timeScale go to 1
			Time.timeScale=1.0f;
			//message to begin 
			Debug.Log("begin");	
		}

		transform.Translate (new Vector2 (1, 0) * moveSpeed * Time.deltaTime);

	}

	//Used for checking if the player is touching the ground 
	void OnCollisionStay2D (Collision2D coll)
	{
		if (coll.gameObject.tag == "Ground" &&(Input.GetKey(KeyCode.Space)))
		{
			//Jump Script
			rigidbody2D.AddForce(new Vector2(0f, jumpSpeed));
			
		}
	}

	// Used for checking if player collided with object
	void OnCollisionEnter2D(Collision2D coll) {
		if (coll.gameObject.tag == "Obstaculo")
			coll.gameObject.SendMessage("Dead");
		
	}


}
